﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="SearchOption.ascx.vb"
    Inherits="WebForm_ManageFinanceYTDReport_SearchOption" %>

<script runat="server">
    Protected Sub ddlYear_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
        For i As Integer = DateTime.Now.Year To BaseYear Step -1
            TryCast(sender, ListControl).Items.Add(i)
        Next
    End Sub
    
    Protected Sub ddlMonth_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
        For i As Integer = 1 To 12
            TryCast(sender, ListControl).Items.Add(New ListItem(i.ToString("00"), i))
        Next
    End Sub
    
    Protected Sub ddlSignature_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ddlControl As DropDownList = Me.ddlSignature
        Dim stManager As New SignatureManager

        TryCast(sender, ListControl).DataTextField = "Description"
        TryCast(sender, ListControl).DataValueField = "Signature"
        TryCast(sender, ListControl).DataSource = stManager.GetAllSignatureFormatted(Me.Division)
    End Sub

    Protected Sub ddlSignature_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
        TryCast(sender, ListControl).Items.Insert(0, New ListItem("-Total-", ""))
    End Sub    

    Protected Sub ddlChannel_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cmanager As New ChannelManager
        Dim ddlControl As DropDownList = Me.ddlChannel

        ddlControl.DataSource = cmanager.GetAll(Me.Division, ddlSignature.Text)
        ddlControl.DataTextField = "ChannelName"
        ddlControl.DataValueField = "Channel"
        'ddlControl.DataBind()
    End Sub

    Protected Sub ddlChannel_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
        'Group Channel Data
        Dim cmanager As New ChannelManager
        cmanager.SetDDLGroupChannel(TryCast(sender, ListControl), Me.Division)
        
        TryCast(sender, ListControl).Items.Insert(0, MyObj.GetDDLSelectAllItemV2)
    End Sub
    
    Protected Sub ddlHier1_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
        ddlHier1.DataSource = New DataTable
        
        If ddlSignature.Text = String.Empty Then
            Return
        End If
        
        If ddlChannel.Text = String.Empty Then
            Return
        End If
        
        Dim dat As New clsData
        Dim sql As New StringBuilder
        Dim dt As New DataTable
        Dim paras As New List(Of SqlParameter)

        'Group Channel
        sql.AppendFormat("Select channel, c_hier_1, c_hier_1name from ChannelHier1View ch ")
        sql.AppendFormat("where division = @division AND c_hier_1 <> '' ")
        paras.Add(New SqlParameter("division", Me.Division))
        
        sql.AppendFormat("AND ch.signature = @signature ")
        paras.Add(New SqlParameter("signature", ddlSignature.Text))
        
        sql.AppendFormat("AND ch.channel = @channel ")
        paras.Add(New SqlParameter("channel", ddlChannel.Text))

        dt = dat.GetData(sql.ToString(), paras.ToArray)

        ddlHier1.DataTextField = "c_hier_1Name"
        ddlHier1.DataValueField = "c_hier_1"
        ddlHier1.DataSource = dt
    End Sub

    Protected Sub ddlHier1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
        If ddlHier1.Items.FindByValue(MyObj.GetDDLSelectAllItemV2.Value) Is Nothing Then
            ddlHier1.Items.Insert(0, MyObj.GetDDLSelectAllItemV2())
        End If
    End Sub
</script>

<div style="background-color: #170D0F" align="left">
    <asp:Panel ID="pnlPlus" runat="server">
        <table width="50px">
            <tr>
                <td align="left">
                    <asp:ImageButton ID="imgPlus" runat="server" SkinID="minus" />
                    <asp:LinkButton ID="lbtnViewContent" runat="server"></asp:LinkButton>
                </td>
            </tr>
        </table>
    </asp:Panel>
    <asp:Panel ID="pnlMinus" runat="server">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <fieldset id="pnlSelect" style="border-color: #4E333B" runat="server">
                    <legend class="white2">Select</legend>
                    <table>
                        <tr>
                            <td>
                                <fieldset id="plVersion" style="border-color: #4E333B" runat="server">
                                    <legend class="white2">
                                        <asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:report, plVersion%>" />
                                    </legend>
                                    <table align="left" border="0" cellspacing="0">
                                        <tr>
                                            <td align="left">
                                                &nbsp;&nbsp;<asp:Label ID="lblYear" Font-Bold="true" runat="server" meta:resourcekey="lblYear"></asp:Label>
                                            </td>
                                            <td colspan="3">
                                                <asp:DropDownList ID="ddlYear" runat="server" AutoPostBack="false" OnDataBinding="ddlYear_DataBinding">
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                    </table>
                                    <table align="left" border="0" cellspacing="0">
                                        <tr>
                                            <td align="left">
                                                &nbsp;&nbsp;<asp:Label ID="lblMonth" Font-Bold="true" runat="server" meta:resourcekey="lblMonth"></asp:Label>
                                            </td>
                                            <td colspan="3">
                                                <asp:DropDownList ID="ddlMonth" runat="server" AutoPostBack="false" OnDataBinding="ddlMonth_DataBinding">
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                    </table>
                                </fieldset>
                                <fieldset id="plData" style="border-color: #4E333B" runat="server">
                                    <legend style="color: Blue">
                                        <asp:Literal ID="Literal2" runat="server" Text="<%$ Resources:report, plData%>" />
                                    </legend>
                                    <table border="0">
                                        <tr>
                                            <td align="right" width="70px">
                                                <asp:Label ID="lblSIgnature" runat="server" Text="Signature"></asp:Label>
                                            </td>
                                            <td align="left">
                                                <asp:DropDownList ID="ddlSignature" runat="server" OnDataBinding="ddlSignature_DataBinding"
                                                     OnDataBound="ddlSignature_DataBound" AutoPostBack="true" OnSelectedIndexChanged="ddlSignature_SelectedIndexChanged">
                                                </asp:DropDownList>
                                                <asp:RequiredFieldValidator ID="rfvNeedSignature" Enabled="false" runat="server"
                                                    ControlToValidate="ddlSignature" Display="None" ValidationGroup="Submit"
                                                    InitialValue="" SetFocusOnError="true" meta:resourcekey="rfvNeedSignature"></asp:RequiredFieldValidator>
                                            </td>
                                            <tr>
                                    </table>
                                </fieldset>
                                <fieldset id="plType" style="border-color: #4E333B" runat="server">
                                    <legend class="white2">
                                        <asp:Literal ID="Literal3" runat="server" Text="<%$ Resources:report, plType%>" />
                                    </legend>
                                    <table align="left" width="100%" border="0" cellspacing="0">
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblChannel" Font-Bold="true" runat="server" Text="<%$Resources:report,lblChannel %>"></asp:Label>
                                                <asp:DropDownList ID="ddlChannel" runat="server" AutoPostBack="true" OnDataBinding="ddlChannel_DataBinding"
                                                     OnDataBound="ddlChannel_DataBound" OnSelectedIndexChanged="ddlChannel_SelectedIndexChanged">
                                                </asp:DropDownList>
                                            </td>
                                            <td align="right">
                                                <asp:Label ID="lblHier1" Font-Bold="true" runat="server" Text="<%$Resources:report,lblHier1 %>"></asp:Label>
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="ddlHier1" runat="server" OnDataBinding="ddlHier1_DataBinding"
                                                     OnDataBound="ddlHier1_DataBound">
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                    </table>
                                </fieldset>
                            </td>
                            <td valign="bottom">
                                <asp:Button ID="btnSubmit" UseSubmitBehavior="false" runat="server" ValidationGroup="Submit"
                                    meta:resourcekey="btnSubmit" />
                                <asp:Button ID="btnExportGroupByCG" UseSubmitBehavior="false" SkinID="button2" ValidationGroup="Submit"
                                    runat="server" meta:resourcekey="btnExportGroupByCG" />
                                <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
                                    ShowSummary="false" ValidationGroup="Submit" />
                                <asp:HiddenField ID="hf_ActualSecondValue" runat="server" />
                            </td>
                        </tr>
                    </table>
                </fieldset>
            </ContentTemplate>
            <Triggers>
                <asp:PostBackTrigger ControlID="btnSubmit" />
                <asp:PostBackTrigger ControlID="btnExportGroupByCG" />
            </Triggers>
        </asp:UpdatePanel>
    </asp:Panel>
</div>
<ajaxToolkit:CollapsiblePanelExtender ID="cpeDemo" SkinID="normal" runat="Server"
    TargetControlID="pnlMinus" ExpandControlID="pnlPlus" CollapseControlID="pnlPlus"
    Collapsed="false" TextLabelID="lbtnViewContent" ImageControlID="imgPlus" ExpandedText="Hide"
    CollapsedText="Show">
</ajaxToolkit:CollapsiblePanelExtender>
